package sample;

import com.drew.imaging.tiff.TiffMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.sun.media.jai.codec.*;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * User: yaung
 * Date: 2016/10/4
 * Time: 20:01
 * To change this template use File | Settings | File Templates.
 */
public class TifTest {
    public static void main(String[] args) throws IOException {
        //tif judge

        File file = new File("E:\\zone\\migrate\\excel\\0\\0_1.tif");
        SeekableStream s = null;
        TIFFDecodeParam param = null;
        try {
            s = new FileSeekableStream(file);
            ImageDecoder dec = ImageCodec.createImageDecoder("tiff", s, param);
            int numofpages;
            String[] a = dec.decodeAsRenderedImage().getPropertyNames();
            numofpages = dec.getNumPages();
            System.out.println(numofpages);
        } catch (IOException e1) {
            e1.printStackTrace();
        }

//        X Resolution : 300 dots per inch
//        Y Resolution : 300 dots per inch
//        Thumbnail Compression : T6/Group 4 Fax
//        X Resolution : 300 dots per inch
//        Y Resolution : 300 dots per inch
        File jpegFile = new File("C:\\Users\\Administrator\\Desktop\\jmj\\进馆扫描\\39\\39_1.tif");
        Metadata metadata = TiffMetadataReader.readMetadata(jpegFile);
        Iterable<Directory> a = metadata.getDirectories();
        for (Directory directory : a) {
            Iterator<Tag> tag = directory.getTags().iterator();
            while (tag.hasNext()) {
                Tag tag1 = tag.next();
//                if(tag1.getTagName().indexOf("X Resolution") >= 0 ||
//                        tag1.getTagName().indexOf("Y Resolution") >= 0 ||
//                        tag1.getTagName().indexOf("Compression") >= 0  )
                System.out.println(tag1.getTagName() + " : " +tag1.getDescription());
            }
        }
    }
}
